// ---------------------------------------------------------------------
//
// -- 地区排行榜面板
// -- author £
//
// ---------------------------------------------------------------------
const CommonUtil = require('CommonUtil'),
    superClass = require('AlertWindow');

cc.Class({
    extends: superClass,

    properties: {
        sharedView: cc.Sprite,
        rankPanelBg: cc.Node,
        btnPre: cc.Button,
        btnNext: cc.Button,
        btnShare: cc.Node,
        btnReturn: cc.Node,
    },

    ctor: function () {
        this._update = false;
        this._updateCount = 0;
        this.tex = new cc.Texture2D();
        this._uItr = -1;
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        CommonUtil.mysuper(superClass, this, 'onLoad');
        this.rankPanelBg.height += require('UIManager').getRankBgDH(this.btnShare);
        this.sharedView.node.y = require('UIManager').getDesignHC();
        this.sharedView.node.height = require('UIManager').getRealH();

        this.btnPre.node.on('click', this.startUpdate, this);
        this.btnNext.node.on('click', this.startUpdate, this);
    },

    start () {

    },

    show: function (shareTicket) {
        CommonUtil.mysuper(superClass, this, 'show');
        this.startUpdate();
    },

    hide: function (data) {
        CommonUtil.mysuper(superClass, this, 'hide');
        this._update = false;
        this.sharedView.spriteFrame = null;
    },

    startUpdate: function () {
        this._update = true;
        this._updateCount = 0;  
    },

    clear: function () {
    },

    update () {
        if (!this._update) return;

        if (++ this._updateCount === 60)
            this._update = false;

        if (this._uItr !== 3) {
            ++this._uItr;
            return;
        }

        this._uItr = 0;
        require('Platform').updateSub(this.tex, this.sharedView);
    }
});
